package com.k8.common.ioc.processorImpl;

import com.k8.common.annotation.Auto;
import com.k8.common.ioc.BeanPostProcessor;
import com.k8.common.factroy.BeanFactory;
import com.k8.common.aware.BeanFactoryAware;


/*
 * 自动注入，不要添加到spi接口文件
 * */
@Auto
public class BeanFactoryAwarePostProcessor implements BeanPostProcessor {
    BeanFactory beanFactory;

    public BeanFactoryAwarePostProcessor(BeanFactory beanFactory) {
        if (beanFactory == null)
            throw new IllegalArgumentException("BeanFactoryAwarePostProcessor is special postProcessor");
        this.beanFactory = beanFactory;
    }

    @Override
    public <E> E postProcessBeforeInitialization(E bean, String beanName) {
        if (bean instanceof BeanFactoryAware beanFactoryAware) {
            beanFactoryAware.beanFactoryAware(beanFactory);
        }
        return bean;
    }
}
